import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
//准备state对象——保存具体的数据
const state = {
  addRoutes: [], // 动态路由
  axiosCancels: [] // 所有需要取消请求的cancel数组
};
//准备actions对象——响应组件中用户的动作
const actions = {};
//准备mutations对象——修改state中的数据
const mutations = {
  GENERATE_ROUTERS(state, routes) {
    state.addRoutes = routes;
  },
  PUSH_AXIOS_CANCELS(state, cancel) {
    state.axiosCancels.push(cancel);
  },
  SET_AXIOS_CANCELS(state, arr) {
    state.axiosCancels = arr
  }
};
//创建并暴露store
const getters = {};
export default new Vuex.Store({
  actions,
  mutations,
  state,
  getters
});
